Code coverage report for src/helpers/debounce.js

Statements: 96.15% (25 / 26)      Branches: 68.75% (11 / 16)      Functions: 100% (8 / 8)      Lines: 96.15% (25 / 26)      Ignored: none     

All files » src/helpers/ » debounce.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56    1         9 11 11 30     30 26   30 1 1 1     30     30                 4 3 3 3 2   2 1 1   1 1 1 1                
'use strict';
 
angular.module('mgcrea.ngStrap.helpers.debounce', [])
 
// @source jashkenas/underscore
// @url https://github.com/jashkenas/underscore/blob/1.5.2/underscore.js#L693
.factory('debounce', function($timeout) {
  return function(func, wait, immediate) {
    var timeout = null;
    return function() {
      var context = this,
        args = arguments,
        callNow = immediate && !timeout;
      if(timeout) {
        $timeout.cancel(timeout);
      }
      timeout = $timeout(function later() {
        timeout = null;
        Eif(!immediate) {
          func.apply(context, args);
        }
      }, wait, false);
      Iif(callNow) {
        func.apply(context, args);
      }
      return timeout;
    };
  };
})
 
 
// @source jashkenas/underscore
// @url https://github.com/jashkenas/underscore/blob/1.5.2/underscore.js#L661
.factory('throttle', function($timeout) {
  return function(func, wait, options) {
    var timeout = null;
    options || (options = {});
    return function() {
      var context = this,
        args = arguments;
      if(!timeout) {
        Eif(options.leading !== false) {
          func.apply(context, args);
        }
        timeout = $timeout(function later() {
          timeout = null;
          Eif(options.trailing !== false) {
            func.apply(context, args);
          }
        }, wait, false);
      }
    };
  };
});